import Vue from 'vue'
const install = () => {
    //自定义请求分页方法
    Vue.prototype.zpost = function (url, pageIndex, search) {
        const params = new URLSearchParams();
        if (search) {
            params.append("search", JSON.stringify(search));
        }
        params.append("pageSize", 5);
        params.append(
            "pageNum",
            pageIndex == "" || typeof pageIndex == "undefined"
                ? 1
                : pageIndex
        );
        return this.$http
            .post(url, params)
            .then(res => {
                if (res.status == 200) {
                    res = res.data.data;
                    return {
                        total: parseInt(res.total),
                        tableData: res.list
                    }

                }
            })
            .catch(err => { });

    };
    Vue.prototype.zadd = function (url, data) {
        // const params = new URLSearchParams();
        // for (var x in data){
        //     params.append(x,data[x]);
        // }

        return this.$http
            .post(url, JSON.stringify(data), { headers: { "Content-Type": "application/json" } })
            .then(res => {
                if (res.status == 200) {
                    return { status: res.status, data: res.data.data }
                }
            })
            .catch(err => {
                //console.log(err);
                return Promise.reject(err);
            });
    }
    Vue.prototype.zdel = function (url, userId) {
        //  console.log(index, row);
        this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
        })
            .then(() => {
                //  const params = new URLSearchParams();
                let params = { "id": userId };
                return this.$http
                    .post(url, JSON.stringify(params), { headers: { "Content-Type": "application/json" } })
                    .then(res => {
                        if (res.status == 200) {
                            this.$message({
                                type: "success",
                                message: "删除成功!"
                            });
                            this.getList();
                        } else {
                            this.$message({
                                type: "info",
                                message: "已取消删除"
                            });
                        }
                    })
                    .catch(err => { });

            })
            .catch(() => {
                this.$message({
                    type: "info",
                    message: "已取消删除"
                });
            });
    }

};
export default install
